package org.poker.prophecy.simulation.gui;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTextPane;
import javax.swing.JLabel;

import org.poker.prophecy.ImagesManager;
import org.poker.prophecy.core.Card;
import org.poker.prophecy.core.PocketCards;

import com.kitfox.svg.app.beans.SVGIcon;

import java.awt.GridBagConstraints;
import java.awt.Insets;

public class TableSeat extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTextPane TalkBox = null;
	private JLabel PlayerLabel = null;
	private JLabel HandCard1 = null;
	private JLabel HandCard2 = null;
	private JLabel ChipsAmount = null;	

	/**
	 * This is the default constructor
	 */
	public TableSeat() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.insets = new Insets(5, 0, 5, 0);
		gridBagConstraints4.gridy = 1;
		gridBagConstraints4.ipadx = 0;
		gridBagConstraints4.ipady = 0;
		gridBagConstraints4.fill = GridBagConstraints.BOTH;
		gridBagConstraints4.weightx = 1.0;
		gridBagConstraints4.weighty = 1.0;
		gridBagConstraints4.gridx = 2;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.insets = new Insets(5, 10, 5, 10);
		gridBagConstraints3.gridy = 1;
		gridBagConstraints3.ipadx = 0;
		gridBagConstraints3.ipady = 0;
		gridBagConstraints3.gridwidth = 2;
		gridBagConstraints3.fill = GridBagConstraints.BOTH;
		gridBagConstraints3.gridheight = 1;
		gridBagConstraints3.weightx = 1.0;
		gridBagConstraints3.weighty = 1.0;
		gridBagConstraints3.anchor = GridBagConstraints.CENTER;
		gridBagConstraints3.gridx = 0;
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.insets = new Insets(5, 5, 5, 10);
		gridBagConstraints2.gridy = 1;
		gridBagConstraints2.ipadx = 0;
		gridBagConstraints2.ipady = 0;
		gridBagConstraints2.fill = GridBagConstraints.BOTH;
		gridBagConstraints2.weightx = 1.0;
		gridBagConstraints2.weighty = 1.0;
		gridBagConstraints2.gridx = 3;
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.insets = new Insets(5, 10, 5, 10);
		gridBagConstraints1.gridy = 3;
		gridBagConstraints1.ipadx = 0;
		gridBagConstraints1.ipady = 0;
		gridBagConstraints1.gridwidth = 4;
		gridBagConstraints1.weightx = 1.0;
		gridBagConstraints1.weighty = 1.0;
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
		gridBagConstraints1.gridx = 0;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.fill = GridBagConstraints.BOTH;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.ipadx = 0;
		gridBagConstraints.ipady = 0;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.weighty = 1.0;
		gridBagConstraints.gridwidth = 4;
		gridBagConstraints.insets = new Insets(5, 10, 5, 10);
		
		PlayerLabel = new JLabel();
		PlayerLabel.setText("no player");
		PlayerLabel.setVerticalAlignment(JLabel.CENTER);
		PlayerLabel.setHorizontalAlignment(JLabel.CENTER);
		PlayerLabel.setIcon(ImagesManager.getPlayerImageIcon("empty"));
		PlayerLabel.setVerticalTextPosition(JLabel.TOP);
		PlayerLabel.setHorizontalTextPosition(JLabel.CENTER);

		HandCard1 = new JLabel();
		HandCard1.setPreferredSize(new Dimension(45, 63));

		HandCard2 = new JLabel();
		HandCard2.setPreferredSize(new Dimension(45, 63));
		
		ChipsAmount = new JLabel();
		ChipsAmount.setText("");

		this.setLayout(new GridBagLayout());
		this.setSize(209, 300);
		this.add(getTalkBox(), gridBagConstraints);
		this.add(HandCard1, gridBagConstraints4);
		this.add(HandCard2, gridBagConstraints2);
		this.add(PlayerLabel, gridBagConstraints3);
		this.add(ChipsAmount, gridBagConstraints1);
	}

	/**
	 * This method initializes TalkBox	
	 * 	
	 * @return javax.swing.JTextPane	
	 */
	private JTextPane getTalkBox() {
		if (TalkBox == null) {
			TalkBox = new JTextPane();
		}
		return TalkBox;
	}

	
	public void setPlayerName(String name){
		this.PlayerLabel.setText(name);
	}
	
	public void setPlayerIcon(Icon icon){
		this.PlayerLabel.setIcon(icon);
	}
	
	public void setPocketCards(PocketCards pocketCards){
		if(pocketCards != null){
			this.HandCard1.setIcon(ImagesManager.getJpgImageIconForCard(pocketCards.getCard1()));
			this.HandCard2.setIcon(ImagesManager.getJpgImageIconForCard(pocketCards.getCard2()));
		}else{
			this.clearPocketCards();
		}
	}
	
	public void clearPocketCards(){
		this.HandCard1.setIcon(null);
		this.HandCard2.setIcon(null);
	}
	
	public void setPlayerChips(int amount){
		this.ChipsAmount.setText("$ " + amount);
	}
	
	public void setTalkBox(String text){
		this.TalkBox.setText(text);
	}
	
}  //  @jve:decl-index=0:visual-constraint="29,15"
